/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.manchester.biology.eqhei.persistence;

import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author mlwyatt
 */
@Entity
@Table(name = "Security")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Security.findAll", query = "SELECT s FROM Security s"),
    @NamedQuery(name = "Security.findByUserName", query = "SELECT s FROM Security s WHERE s.userName = :userName"),
    @NamedQuery(name = "Security.findByGroupid", query = "SELECT s FROM Security s WHERE s.groupid = :groupid")})
public class Security implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 50)
    @Column(name = "userName")
    private String userName;
    @Lob
    @Column(name = "stamp")
    private byte[] stamp;
    @Lob
    @Column(name = "passcode")
    private byte[] passcode;
    @Size(max = 50)
    @Column(name = "groupid")
    private String groupid;
    @OneToOne(cascade = CascadeType.ALL, mappedBy = "security")
    private User user;

    public Security() {
    }

    public Security(String userName) {
        this.userName = userName;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public byte[] getStamp() {
        return stamp;
    }

    public void setStamp(byte[] stamp) {
        this.stamp = stamp;
    }

    public byte[] getPasscode() {
        return passcode;
    }

    public void setPasscode(byte[] passcode) {
        this.passcode = passcode;
    }

    public String getGroupid() {
        return groupid;
    }

    public void setGroupid(String groupid) {
        this.groupid = groupid;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (userName != null ? userName.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Security)) {
            return false;
        }
        Security other = (Security) object;
        if ((this.userName == null && other.userName != null) || (this.userName != null && !this.userName.equals(other.userName))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "edu.manchester.biology.eqhei.business.Security[ userName=" + userName + " ]";
    }
    
}
